
//------------------------------------------------------------------------------

String.prototype.valueSafe = function(){
	return this.replace(/\"/g, '&quot;');
};

//------------------------------------------------------------------------------

String.prototype.urlEncode = function(){
	return encodeURI(this);
};

//------------------------------------------------------------------------------

String.prototype.urlDecode = function(){
	return decodeURI(this);
};

//------------------------------------------------------------------------------

String.prototype.repeat = function(count){
	if ( 1 > count ) {
		return '';
	}
	
	value = this.valueOf();
	var retval = '';
	
	while ( count > 0 ) {
		if ( count & 1 ) {
			retval += value;
		}
		count >>= 1;
		value += value;
	}
	return retval;
};

//------------------------------------------------------------------------------

String.prototype.beginsWith = function(str) {
	return ( this.substr(0, str.length) == str );
};

//------------------------------------------------------------------------------

String.prototype.endsWith = function(str){
	return ( this.substring(this.length - str.length, this.length) == str );
};

//------------------------------------------------------------------------------

/**
 * If the string begnis with given substring, then it is removed.
 * @param string str
 * @param bool repeat
 * @returns void
 */
String.prototype.cutFromBeg = function(str, repeat){
	if ( undefined == repeat ) {
		repeat = true;
	}
	var retval = this;
	while ( retval.beginsWith(str) ) {
		retval = retval.substring(str.length, retval.length);
		if ( ! repeat ) {
			break;
		}
	}
	return retval;
};

//------------------------------------------------------------------------------

String.prototype.cutFromEnd = function(str, repeat){
	if ( undefined == repeat ) {
		repeat = true;
	}
	var retval = this;
	while ( retval.endsWith(str) ) {
		retval = retval.substring(0, retval.length - str.length);
		if ( ! repeat ) {
			break;
		}
	}
	return retval;
};

//------------------------------------------------------------------------------

String.prototype.cutFromBoth = function(str, repeat){
	return this.cutFromBeg(str, repeat).cutFromEnd(str, repeat);
};

//------------------------------------------------------------------------------